package com.yc.boot.sys.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.boot.common.model.response.Outcome;
import com.yc.boot.sys.entity.SysDictionaries;
import com.yc.boot.sys.business.SysDictionariesBusiness;
import com.yc.boot.sys.model.find.FindDictPage;
import com.yc.boot.sys.model.save.SaveDict;
import com.yc.boot.sys.model.update.UpdateDict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @author 杨智杰
 * @since 2021/8/19 8:53
 */
@Api(tags = "字典相关接口")
@RestController
@RequestMapping("/sys/dictionaries")
public class SysDictionariesApi {

    @Resource
    private SysDictionariesBusiness sysDictionariesBusiness;

    @GetMapping
    @ApiOperation("查询")
    public Outcome<IPage<SysDictionaries>> page(FindDictPage param) {
        return Outcome.success(sysDictionariesBusiness.page(param));
    }

    @PostMapping
    @ApiOperation("新增")
    public Outcome save(@RequestBody @Valid SaveDict param){
        return Outcome.status(sysDictionariesBusiness.save(param));
    }

    @PutMapping
    @ApiOperation("修改")
    public Outcome update(@RequestBody @Valid UpdateDict param){
        return Outcome.status(sysDictionariesBusiness.update(param));
    }

    @DeleteMapping
    @ApiOperation("删除")
    public Outcome delete(@RequestBody @Valid @Size(min = 1) List<Long> id){
        return Outcome.status(sysDictionariesBusiness.delete(id));
    }
}
